package com.wake.mycomposebook.ui.home.list.my.vertical

import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.wake.data.DemoDataProvider
import com.wake.data.model.Tweet
import com.wake.myapplication.VerticalGrid
import com.wake.mycomposebook.ui.home.list.my.horizontal.CardItem
import com.wake.theme.modifier.instagramGradient

/**
 *@author created by WA03675
 *@date  2022-04-14 17:03
 *@des
 */

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MyGridList() {
    val list = remember {
        DemoDataProvider.itemList.take(4)
    }

    val tween = remember {
        DemoDataProvider.tweetList
    }


    Column(
        modifier = Modifier
            .verticalScroll(rememberScrollState())
            .fillMaxSize()
    ) {
        VerticalGrid(columns = 2) {
            list.forEach {
                CardItem(it = it)
            }

        }
        VerticalGrid(columns = 4) {
            tween.forEach {
                GridHeaderItem(it)
            }
        }

        //            LazyVerticalGrid(cells = GridCells.Fixed(2), content = {
//            items(list) {
//                CardItem(it)
//            }
//        })
////
////        LazyVerticalGrid(cells = GridCells.Fixed(4), content = {
////            items(tween) {
////                GridHeaderItem(it)
////            }
////        })
    }
}

@Composable
fun GridHeaderItem(it: Tweet) {

    Column(horizontalAlignment = Alignment.CenterHorizontally) {

        androidx.compose.material.Surface(
            modifier = Modifier
                .width(50.dp)
                .height(50.dp)
                .background(Brush.linearGradient(instagramGradient, Offset(0f, 0f), Offset(100f, 100f))),
            shape = CircleShape
        ) {
            Image(painter = painterResource(id = it.authorImageId), contentDescription = null, contentScale = ContentScale.Crop)
        }
        Text(text = it.author, style = MaterialTheme.typography.bodyMedium)
    }
}

@Composable
@Preview
fun MyGrid() {
    MyGridList()
}